package com.example.build_input.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.build_input.R;
import com.example.build_input.entity.Study;
import com.example.build_input.utils.FilePath;

import java.util.List;

public class StudyAdapter extends BaseAdapter {
    private Context mContext;
    private List<Study> mList;


    public StudyAdapter(Context context, List list){
        mContext = context;
        mList=list;
    }
    @Override//返回图片数组长度
    public int getCount() {
        return mList.size();
    }
    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }
    @Override
    public long getItemId(int position) {
        return position;
    }
    //创建一个新的ImageView，用来显示图片，并且将这个图片
    //通过适配器加载到新的ImageView中
    @SuppressLint("SetTextI18n")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


        ViewHolde viewHolde = null;

        if (null ==convertView) {
            // 实例化 ViewHolde对象

            viewHolde =new ViewHolde();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.adapter_study,null);
            viewHolde.tv_img=convertView.findViewById(R.id.iv_img);
            viewHolde.tv_fileName =(TextView) convertView.findViewById(R.id.tv_fileName);
            viewHolde.tv_update =(TextView) convertView.findViewById(R.id.tv_update);
            viewHolde.tv_fileSize =(TextView) convertView.findViewById(R.id.tv_fileSize);


            convertView.setTag(viewHolde);

        } else {
            viewHolde = (ViewHolde)convertView.getTag();
        }

        Study study= mList.get(position);
        viewHolde.tv_fileName.setText("文件名称："+study.getName());
        viewHolde.tv_update.setText("修改时间："+study.getUpdateTime());
        viewHolde.tv_fileSize.setText("文件大小："+study.getFileSize());

//        String extension= FilePath.getExtFromFilename(study.getName());
        viewHolde.tv_img.setImageResource(R.drawable.file2);


        // 返回item视图
        return convertView;
    }
    static class ViewHolde {
        ImageView tv_img;
        TextView tv_fileName;
        TextView tv_update;
        TextView tv_fileSize;


    }
}
